//战役计分引擎

var BattleScore = function(duration, casualty, gainArea, score){
	this.duration = duration;
	this.casualty = casualty;
	this.gainArea = gainArea;
	this.score = score;
};

var CalcBattleScore = function(){
	var originMan = [];
	var tgtMan = [];
	
	var originStrength = [];
	var tgtStrength = [];
	var tgtTotalStrength = 0;
	
	var originArea = [];
	var tgtArea = [];
	
	var troopOri = campaign_ori.troop;
	var troop = campaign.troop;
	
	for (var forceid = 0; forceid < campaign.force.length; forceid++){
		originMan[forceid] = 0;
		tgtMan[forceid] = 0;
		originStrength[forceid] = 0;
		tgtStrength[forceid] = 0;
		originArea[forceid] = 0;
		tgtArea[forceid] = 0;
	}
	
	for (var troopid = 0; troopid < troopOri.length; troopid++){
		var forceid = troopOri[troopid].force;
		originStrength[forceid] += troopOri[troopid].strength;
		tgtStrength[forceid] += troop[troopid].strength;
		tgtTotalStrength += troop[troopid].strength;
		
		originMan[forceid] += originStrength[forceid] * troopOri[troopid].man_strength;
		tgtMan[forceid] += tgtStrength[forceid] * troop[troopid].man_strength;
	}

	var originCapture = new ForceCapture(campaign_ori, tileEngine);
	var tgtCapture = new ForceCapture(campaign, tileEngine);
	
	for (var tileIndex = 0; tileIndex < originCapture.forceMap.length; tileIndex++){
		originArea[originCapture.forceMap[tileIndex]] += 1;
		tgtArea[tgtCapture.forceMap[tileIndex]] += 1;
	}
	
	var duration = campaign.time_ref.current_step * campaign.time_ref.time_of_step;
	var casualty = [];
	var gainArea = [];
	var score = [];
	
	for (var forceid = 0; forceid < campaign.force.length; forceid++){
		casualty[forceid] = originMan[forceid] - tgtMan[forceid];
		gainArea[forceid] = (tgtArea[forceid] - originArea[forceid]) * campaign.zone.tile_area;
		score[forceid] = 800000 * (tgtArea[forceid] / (campaign.zone.xsize * campaign.zone.ysize))
			+ 200000 * (tgtStrength[forceid] / tgtTotalStrength);
	}
	
	return new BattleScore(duration, casualty, gainArea, score);
};